package com.ncu.music_notification;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.media.Image;
import android.os.Bundle;
import android.os.IBinder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

public class MusicFragment extends Fragment {
    private View view;
    private Intent svIntent;

    //绑定和解绑定必须的serviceconneion的接口对象
    private ServiceConnection sc = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };

    public MusicFragment(Context context){
        svIntent = new Intent("com.ncu.music_notification.MusicServer");
        svIntent.setPackage("com.ncu.music_notification");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        view = inflater.inflate(R.layout.notification,container,false);
        TextView tvMsg = (TextView)view.findViewById(R.id.tv_msg);
        ImageView btnPlay = (ImageView)view.findViewById(R.id.btn_play);
        ImageView btnStop = (ImageView)view.findViewById(R.id.btn_pause);
        ImageView btnClose = (ImageView)view.findViewById(R.id.btn_close);
        btnClose.setVisibility(view.GONE);
        ImageView btnApp = (ImageView)view.findViewById(R.id.iv_icon);
        btnApp.setVisibility(view.GONE);

        tvMsg.setText("music.mp3");

        btnPlay.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                getActivity().startService(svIntent);
            }
        });

        btnStop.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                getActivity().stopService(svIntent);
            }
        });
        return view;
    }
}

